package com.qfedu.service.impl;

import com.qfedu.mapper.ContractorMapper;
import com.qfedu.mapper.ContractorMapper;
import com.qfedu.model.Contractor;
import com.qfedu.model.Contractor;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.ContractorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class ContractorServiceImpl implements ContractorService {
    @Autowired
    private ContractorMapper contractorMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = contractorMapper.count();
        pageResult.setTotal(count);
        List<Contractor> page = contractorMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addContractor(Contractor contractor) {
        contractor.setUpdatetime(new Date());
        return contractorMapper.addContractor(contractor);
    }

    @Override
    public Contractor findById(String iid) {
        return   contractorMapper.findById(iid);
    }

    @Override
    public int editContractor(Contractor contractor) {
        contractor.setUpdatetime(new Date());
        int i = contractorMapper.editContractor(contractor);
        return i;
    }

    @Override
    public int deleteByIid(String iid) {
        return contractorMapper.deleteByIid(iid);
    }
}